n = input()
s = []
if len(n) != 4 or (not n.isdigit()):
    print('0')
else:
    n1 = n[0] + n[1]
    Fl = 1
    for i in range(2, int(n1)):
        if int(n1) % i == 0:
            Fl = 0
            break
    if Fl == 1:
        s.append(int(n1))
    n2 = n[0]
    Fl = 1
    for i in range(2, int(n2)):
        if int(n2) % i == 0:
            Fl = 0
            break
    if Fl == 1:
        s.append(int(n2))
    n3 = n[1]
    Fl = 1
    for i in range(2, int(n3)):
        if int(n3) % i == 0:
            Fl = 0
            break
    if Fl == 1:
        s.append(int(n3))
    n4 = n[2]
    Fl = 1
    for i in range(2, int(n4)):
        if int(n4) % i == 0:
            Fl = 0
            break
    if Fl == 1:
        s.append(int(n4))
    n5 = n[3]
    Fl = 1
    for i in range(2, int(n5)):
        if int(n5) % i == 0:
            Fl = 0
            break
    if Fl == 1:
        s.append(int(n5))
    n6 = n[1] + n[2]
    Fl = 1
    for i in range(2, int(n6)):
        if int(n6) % i == 0:
            Fl = 0
            break
    if Fl == 1:
        s.append(int(n6))
    n7 = n[2] + n[3]
    Fl = 1
    for i in range(2, int(n7)):
        if int(n7) % i == 0:
            Fl = 0
            break
            c.append(int(n7))
    if Fl == 1:
        s.append(int(n7))
    n8 = n[2] + n[3]
    Fl = 1
    for i in range(2, int(n8)):
        if int(n8) % i == 0:
            Fl = 0
            break
    if Fl == 1:
        s.append(int(n8))
    n9 = n[0] + n[1] + n[2]
    Fl = 1
    for i in range(2, int(n9)):
        if int(n9) % i == 0:
            Fl = 0
            break
    if Fl == 1:
        s.append(int(n9))
    n10 = n[0] + n[1] + n[2] + n[3]
    Fl = 1
    for i in range(2, int(n10)):
        if int(n10) % i == 0:
            Fl = 0
            break
    if Fl == 1:
        s.append(int(n10))
    n11 = n[1] + n[2] + n[3]
    Fl = 1
    for i in range(2, int(n11)):
        if int(n11) % i == 0:
            Fl = 0
            break
    if Fl == 1:
        s.append(int(n11))
    if len(s) == 0:
        print('0')
    else:
        print(max(s))




